/*     */ package com.cr.web.controller.tool;
/*     */ 
/*     */ import com.cr.common.core.controller.BaseController;
/*     */ import com.cr.common.core.domain.AjaxResult;
/*     */ import com.cr.common.utils.MyStringUtils;
import org.apache.commons.lang3.StringUtils;
/*     */ import io.swagger.annotations.Api;
/*     */ import io.swagger.annotations.ApiImplicitParam;
/*     */ import io.swagger.annotations.ApiImplicitParams;
/*     */ import io.swagger.annotations.ApiOperation;
/*     */ import java.util.ArrayList;
/*     */ import java.util.LinkedHashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.springframework.web.bind.annotation.DeleteMapping;
/*     */ import org.springframework.web.bind.annotation.GetMapping;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.PostMapping;
/*     */ import org.springframework.web.bind.annotation.PutMapping;
/*     */ import org.springframework.web.bind.annotation.RequestBody;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.RestController;
/*     */ 
/*     */ @Api("用户信息管理")
/*     */ @RestController
/*     */ @RequestMapping({"/test/user"})
/*     */ public class TestController extends BaseController {
/*     */   public TestController() {
/*  37 */     users.put(Integer.valueOf(1), new UserEntity(Integer.valueOf(1), "admin", "admin123", "15888888888"));
/*  38 */     users.put(Integer.valueOf(2), new UserEntity(Integer.valueOf(2), "ry", "admin123", "15666666666"));
/*     */   }
/*     */   
/*     */   private static final Map<Integer, UserEntity> users = new LinkedHashMap<>();
/*     */   
/*     */   @ApiOperation("获取用户列表")
/*     */   @GetMapping({"/list"})
/*     */   public AjaxResult userList() {
/*  45 */     List<UserEntity> userList = new ArrayList<>(users.values());
/*  46 */     return AjaxResult.success(userList);
/*     */   }
/*     */   
/*     */   @ApiOperation("获取用户详细")
/*     */   @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path")
/*     */   @GetMapping({"/{userId}"})
/*     */   public AjaxResult getUser(@PathVariable Integer userId) {
/*  54 */     if (!users.isEmpty() && users.containsKey(userId))
/*  56 */       return AjaxResult.success(users.get(userId)); 
/*  60 */     return error("用户不存在");
/*     */   }
/*     */   
/*     */   @ApiOperation("新增用户")
/*     */   @ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer"), @ApiImplicitParam(name = "username", value = "用户名称", dataType = "String"), @ApiImplicitParam(name = "password", value = "用户密码", dataType = "String"), @ApiImplicitParam(name = "mobile", value = "用户手机", dataType = "String")})
/*     */   @PostMapping({"/save"})
/*     */   public AjaxResult save(UserEntity user) {
/*  74 */     if (MyStringUtils.isNull(user) || MyStringUtils.isNull(user.getUserId()))
/*  76 */       return error("用户ID不能为空"); 
/*  78 */     return AjaxResult.success(users.put(user.getUserId(), user));
/*     */   }
/*     */   
/*     */   @ApiOperation("更新用户")
/*     */   @PutMapping({"/update"})
/*     */   public AjaxResult update(@RequestBody UserEntity user) {
/*  85 */     if (MyStringUtils.isNull(user) || MyStringUtils.isNull(user.getUserId()))
/*  87 */       return error("用户ID不能为空"); 
/*  89 */     if (users.isEmpty() || !users.containsKey(user.getUserId()))
/*  91 */       return error("用户不存在"); 
/*  93 */     users.remove(user.getUserId());
/*  94 */     return AjaxResult.success(users.put(user.getUserId(), user));
/*     */   }
/*     */   
/*     */   @ApiOperation("删除用户信息")
/*     */   @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path")
/*     */   @DeleteMapping({"/{userId}"})
/*     */   public AjaxResult delete(@PathVariable Integer userId) {
/* 102 */     if (!users.isEmpty() && users.containsKey(userId)) {
/* 104 */       users.remove(userId);
/* 105 */       return success();
/*     */     } 
/* 109 */     return error("用户不存在");
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\classes\com.zip!\com\cr\web\controller\tool\TestController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */